package com.busi.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Map;

public class CoderTest {

	private static final Base64.Encoder encoder = Base64.getEncoder();

	public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
		String s = FileUtil.docx2String(new File("H:\\1111.docx"));
		byte[] b = s.getBytes("UTF-8");
		String encrypt = CertificateCoder.encryptByPublicKey(b);
		System.out.println(encrypt);
		byte[] decrypt = CertificateCoder.decryptByPrivateKey(encrypt);
		System.out.println(new String(decrypt, "UTF-8"));
	}

	public static void test(String s) throws Exception {
		// 生成公钥与私钥
		Map<String, Object> initKeyMap = RSAUtils.initKey(1024);
		// 公钥
		String publicKey = RSAUtils.getPublicKey(initKeyMap);
		// 私钥
		String privateKey = RSAUtils.getPrivateKey(initKeyMap);
		byte[] bytes1 = RSAUtils.encryptByPublicKey(s.toString().getBytes(), publicKey);
		byte[] bytes2 = RSAUtils.decryptByPrivateKey(bytes1, privateKey);
		System.out.println("加密后 ：" + encoder.encodeToString(bytes1));
		System.out.println("解密后 ：" + new String(bytes2));
	}
}
